<%--
  Created by IntelliJ IDEA.
  User: sxs
  Date: 2020/8/8
  Time: 16:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <link rel="stylesheet" href="${AppPath}/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="${AppPath}/css/font-awesome.min.css">
    <link rel="stylesheet" href="${AppPath}/css/main.css">
    <link rel="stylesheet" href="${AppPath}/layer/skin/default/layer.css">
    <style>
        .tree li {
            list-style-type: none;
            cursor:pointer;
        }
        .tree-closed {
            height : 40px;
        }
        .tree-expanded {
            height : auto;
        }
    </style>
</head>

<body>
<!-- 引入头部页面 -->

<div class="container-fluid">
    <div class="row">
        <!-- 引入菜单页面 -->

        <!-- 操作区 -->
        <div>

            <div class="panel panel-default">
                <div class="panel-heading">修改密码<div style="float:right;cursor:pointer;" data-toggle="modal" data-target="#myModal"><i class="glyphicon glyphicon-question-sign"></i></div></div>
                <div class="panel-body">

                        <div class="form-group">
                            <label for="userPwd">请输入你的密码</label>
                            <input type="password" class="form-control" id="userPwd" name="userPwd"  >
                            <input type="hidden" id="userId" name="userId" value="${userId}">
                            <span id="roleNametip"></span>
                        </div>
                        <div class="form-group">
                            <label for="userPwd1">请输入你的新密码</label>
                            <input type="password" class="form-control" id="userPwd1" name="userPwd1"  >

                            <span id="roleNametip1"></span>
                        </div>
                        <div class="form-group">
                            <label for="userPwd2">请确认你的密码</label>
                            <input type="password" class="form-control" id="userPwd2" name="userPwd2"  >
                            <span id="roleNametip2"></span>
                        </div>


                        <button id="updatePwd"  class="btn btn-success"><i class="glyphicon glyphicon-plus"></i> 确认修改</button>
                        <button type="reset" class="btn btn-danger"><i class="glyphicon glyphicon-refresh"></i> 重置</button>

                </div>
            </div>
        </div>
    </div>
</div>
<script src="${AppPath}/jquery/jquery-2.1.1.min.js"></script>
<script src="${AppPath}/bootstrap/js/bootstrap.min.js"></script>
<script src="${AppPath}/script/docs.min.js"></script>
<script src="${AppPath}/layer/layer.js"></script>
<script type="text/javascript" src="${AppPath}/lib/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="${AppPath}/js/index.js"></script>
<script type="text/javascript">
    $(function () {


        ispwd();


        })
    function ispwd(){
        $("#userPwd").blur(function () {
            var zz=/^\w{6,12}$/;
            var userPwd=$(this).val();

            if(zz.test(userPwd)){
                $.ajax({
                    url:"${AppPath}/user/isuserpwd",
                    type:"post",
                    data:{"userPwd":userPwd},
                    success:function (data) {
                        if(data.result=="ok"){

                            $("#roleNametip").html("");
                            return true;
                        }else{

                            $("#roleNametip").html("<font color='red' > 密码输入不正确请重新输入</font>");
                            return false;

                        }
                    }
                })

            }else{

                $("#roleNametip").html("<font color='red' > 密码输入不正确请重新输入</font>");
                return false;
            }

        })

    }
    function ispwd1(){

        var zz=/^\w{6,12}$/;
        var userPwd1=$("#userPwd1").val();
        var userPwd=$("#userPwd").val();
        if(!zz.test(userPwd1)){

            $("#roleNametip1").html("<font color='red' > 用户名密码应大于6位</font>");

            return false;
        }else if(userPwd1==userPwd){

            $("#roleNametip1").html("<font color='red' > 新密码与旧密码不能重复</font>");
            return false;
        }else {
            $("#roleNametip1").html("");
            return true;
        }


    }
    function ispwd2(){
        var userPwd1=$("#userPwd1").val();
        var userPwd2=$("#userPwd2").val();
        if(userPwd1==userPwd2){
            $("#roleNametip2").html("<font color='green' > 密码合理</font>");

            return true;
        }else{
            $("#roleNametip2").html("<font color='red' > 密码确认错误</font>");

            return false;
        }
    }

        $("#updatePwd").click(function () {
           if(ispwd1()) {
               if( ispwd2()) {
                   $.ajax({
                       url:"${AppPath}/user/updateByExample",
                       type:"post",
                       data:{userPwd:$("#userPwd2").val()},
                       success:function (data) {
                           if(data.result=="ok"){
                               layer.msg("密码修改成功,请重新登陆",{time:1000,icon:6},function () {

                                   //关闭当前frame
                                   xadmin.close();

                                   top.location.href="${AppPath}/quit";

                               });
                           }else{
                               layer.msg("密码异常,请重新输入",{time:1500,icon:5,shift:6},function () {

                               });

                           }
                       }
                   })
               }else {
                   layer.msg("请仔细核对密码",{time:1500,icon:5,shift:6},function () {

                   });
               }
           }

    });
</script>
</body>
</html>